package com.satis.compose.get.example.pages

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.satis.compose.get.annotation.PageRoute
import com.satis.compose.get.navigator.LocalPageController
import com.satis.compose.get.widget.GetCenter
import com.satis.compose.get.widget.GetPage
import com.satis.compose.get.widget.GetTopAppBar

/**
 * @author sunshaobei on 2023/3/29
 */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@PageRoute(route = "/compose")
fun ComposePage() {
    val items = arrayListOf<Item>(Item("/app/text", title = "Text"),
        Item("/app/button", title = "button"),
        Item("/app/image", title = "Image"),
        Item("/textField", title = "TextField"),
    )
    GetPage {
       Scaffold(topBar = { GetTopAppBar(title = { Text(text = "Compose Widget", color = Color.White)}) }) {
           LazyColumn(modifier = Modifier.padding(it), contentPadding = PaddingValues(10.dp),verticalArrangement = Arrangement.spacedBy(12.dp)){
               items(items) {
                   Card(
                       modifier = Modifier
                           .fillMaxWidth()
                           .height(50.dp)
                           .clickable {
                               var s  = it.route
                               if (s == "/app/button"){
                                   s = s + "/?ttt=传递的标题参数"
                               }
                               push(s){
                                   launchSingleTop = true
                               }
                           },
                       elevation = 4.dp,
                       shape = RoundedCornerShape(10.dp),
                       backgroundColor = Color.White
                   ) {
                       GetCenter() {
                           Text(text = it.title, color = Color.Black, fontSize = 16.sp)
                       }
                   }
               }
           }
       }
    }
}

data class Item(val route:String,val title:String)